package com.itheima.goods.service.impl;

import com.changgou.goods.pojo.Brand;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.goods.dao.BrandMapper;
import com.itheima.goods.service.BrandService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 版权：(C) 版权所有 2000-2020 上海天好电子商务有限公司苏州分公司
 * <简述>
 * <详细描述>
 *
 * @author LiuShanshan
 * @version $Id$
 */
@Service
public class BrandServiceImpl implements BrandService{

    // Example : 多条件查询，使用example
    //  PageHelper.startPage: 分页使用


    @Autowired
    private BrandMapper brandMapper;

    @Override
    public List<Brand> findAll() {
        return brandMapper.selectAll();
    }

    @Override
    public Brand findById(Integer id) {
        return brandMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer add(Brand brand) {
        int result = brandMapper.insert(brand);
        return Integer.valueOf(result);
    }

    @Override
    public Integer deleteById(Integer id) {
        return brandMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Integer update(Brand brand) {
        PageHelper.clearPage();
        return brandMapper.updateByPrimaryKey(brand);
    }

    @Override
    public PageInfo<Brand> staticPage(int page, int size) {
        //静态分页
        PageHelper.startPage(page,size);
        //分页查询
        return new PageInfo<>(brandMapper.selectAll());
    }

//    @Override
//    public PageInfo<Brand> conditionPage(Brand brand, int page, int size) {
//        //静态分页
//        PageHelper.startPage(page,size);
//        //搜索条件构建
//        Example example = createExample(brand);
//        //分页查询
//        return new PageInfo<>(brandMapper.selectAll());
//    }
}
